<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-wms__locate}">
      <wms-form 
        v-model="dataForm"
        :formList="formList"
        :table-column="tableColumn"
        :advanced="advanced"
        @check-change="checkChange"
        @changeAdvance="changeAdvance"
        @getDataList="getDataList"
        @getReset="getReset"
      >
      <el-form-item>
        <el-button type="primary" plain @click="lock('0')">庫位禁用
        </el-button>
        <el-button type="primary" plain @click="lock('1')">庫位解禁
        </el-button>
      </el-form-item>
      </wms-form>
      
      <wms-table
        ref="wmsTable"
        v-model="dataForm"
        :page="page"
        :total="total"
        :limit="limit"
        :tableData="dataList"
        :table-column="column"
        :module-options="mixinViewModuleOptions"
        :dataListLoading="dataListLoading"
        :showSelection="true"
        @selectChangeHandle="dataListSelectionChangeHandle"
        @pageSizeChangeHandle="pageSizeChangeHandle"
        @pageCurrentChangeHandle="pageCurrentChangeHandle"/>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./components/locate-add-or-update";
import debounce from "lodash/debounce";
import { formList, tableColumn } from './config'
import wmsTable from '@/components/wms-table'
import wmsForm from '@/components/wms-form'
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/wms/locate/page",
        getDataListIsPage: true,
        deleteURL: "/wms/locate",
        deleteIsBatch: true,
      },
      dataForm: {
        dvcNo: '',
        locateNo: '',
        contNo: ''
      },
      formList,
      tableColumn,
      column: [],
      advanced: false,
      lockUrl: '/wms/locate/lock',
      lockForm:{
        locateIds: [],
        lockType: '',
      },
    };
  },
  components: {
    AddOrUpdate,
    wmsTable,
    wmsForm
  },
  methods: {
    lock(lockType){

      if (this.lockForm.locateIds.length==0) {
        this.$message({
          
              message:'请选择貨位',
              type:'error',
              center:true,
              showClose:true
          })
        //this.$refs.callAgvItemID.focus();
      } 
      else
      {
        this.lockForm.lockType = lockType
        this.$http['post'](this.lockUrl, this.lockForm).then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message({
              message: res.msg,
              type: 'error',
              duration: 5000,})
          }
          this.$message({
            message: this.$t('prompt.success'),
            type: 'success',
            duration: 1000,
            onClose: () => {
              this.visible = false
              this.query()
              this.lockForm.locateIds  = []
            }
          })
        }).catch(() => { })
      }

    },

    //0.重置搜索框
    getReset() {
      this.dataForm = this.$options.data().dataForm;
    },
    frobidHandle(id) {
      if (!this.dataForm.locateId) {
        return this.$message({
          message: this.$t('prompt.forbid'),
          type: 'warning',
          duration: 1000
        })
      }
      this.$confirm(this.$t('prompt.info', { 'handle': this.$t('forbid') }), this.$t('prompt.title'), {
        confirmButtonText: this.$t('confirm'),
        cancelButtonText: this.$t('cancel'),
        type: 'warning'
      }).then(() => {
        this.$http.post('/wms/locate/forbid/' + this.dataForm.locateId)
          .then(({ data: res }) => {
            if (res.code != 0) {
              return this.$message.error(res.msg)
            }
            this.$message({
              message: res.msg,
              type: 'success',
              duration: 1000,
              onClose: () => {
                this.getDataList()
              }
            })
          }).catch(() => { })


      }).catch(() => { })

    },
    dataListSelectionChangeHandle(selection, row) {

    if (selection.length > 0) {
      //支持多选
      this.lockForm.locateIds = selection.map(item => item.locateId)
    }
    else
    {
      this.lockForm.locateIds  = []
    }
    
    },
  },
};
</script>
<style>
.right-handle-group {
  float: right;
}
</style>


